<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="false"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
	<head>
		<!-- see from http://tiles.apache.org/tutorial/basic/pages.html for some nice explanations -->
		<title><tiles:getAsString name="title" /></title>
        
        <script type="text/javascript">
            //just in case we do not have a console ...
            if (!window.console){
                window.console = {};

                window.console.log = function(msg){
                    alert(msg);
                };
                
                window.console.error = window.console.log;
            }
        </script>
		
		<!--[if lt IE 9]>
    		<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"></script>
    		<script type="text/javascript">
			    //make sure jq is really loaded from google, else load it from our local server
			    if (!window.jQuery){
			    	console.log("IE < IE 9: load jquery 1.10.2 from local server...");
			        document.write(unescape("%3Cscript src='<%=request.getContextPath() %>/js/jquery-1.10.2.js' type='text/javascript'%3E%3C/script%3E"));
			    }else{
			        console.log("IE < IE 9: we already have jquery "+$().jquery+" (jqQuery 1.10.2 will not be loaded from local server)");
			    }
			</script>
		<![endif]-->
		
		<script type="text/javascript">
		    //make sure jq is really loaded from google, else load it from our local server
			if (!window.jQuery){
				console.log("Try to load jquery 2.0.3 from Google CDN");
				document.write(unescape("%3Cscript src='//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.js' type='text/javascript'%3E%3C/script%3E"));
			} else{
				console.log("we already have jquery "+$().jquery+" (jQuery 2.0.3 will not be loaded from Google CDN)");
			}
		</script>
		
		<script type="text/javascript">
			//if it is still not loaded the load it from own server
			if (!window.jQuery){
				console.log("Try to load jquery 2.0.3 from local server");
				document.write(unescape("%3Cscript src='<%=request.getContextPath() %>/js/jquery-2.0.3.js' type='text/javascript'%3E%3C/script%3E"));
			} else{
				console.log("we already have jquery "+$().jquery +" (jQuery 2.0.3 will not be loaded from local server)");
			}
		</script>
		
		<!-- jquery ui integration from jquery cdn (content delivery network) -->
		<script src="//code.jquery.com/ui/1.10.3/jquery-ui.js" type="text/javascript"></script>
		<link href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css"/>
		<script type="text/javascript">
			//if it is still not loaded the load it from own server
			if (!window.jQuery.ui){
				console.log("Try to load jquery ui 1.10.3 from local server");
				
				//non-blocking loading of css from local server
				var head = document.getElementsByTagName('head')[0];
				var link = document.createElement('link');
				link.href = '<%=request.getContextPath() %>/css/jquery-ui-1.10.3.css';
				link.type = 'text/css';
				link.rel = 'stylesheet';
				head.appendChild(link);
				
				document.write(unescape("%3Cscript src='<%=request.getContextPath() %>/js/jquery-ui-1.10.3.js' type='text/javascript'%3E%3C/script%3E"));
			} else{
				console.log("we already have jquery ui " + window.jQuery.ui.version +" (jQuery ui 1.10.3 will not be loaded from local server)");
			}
		</script>
		
		<script src="<%=request.getContextPath() %>/js/json2.js"></script>
		
		<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/styles.css" />
		
		<s:head/>
		
	</head>
	<body>
		<div class="body">
			
			<div class="header">
				<tiles:insertAttribute name="header" />
			</div>
			
			<div class="content">
				<tiles:insertAttribute name="content" />
			</div>
			
			<div class="footer">
				<tiles:insertAttribute name="footer" />
			</div>
			
		</div>
	</body>
</html>